<?php

class Unit{
	
	private $kd_unit;
	private $unit;
	private $parent;
	private $kd_eselon;
	
	function __construct()
	{
	}
	
	function setId($kd_unit){
	
		$this->kd_unit = $kd_unit;
	}
	
	function setUnit($unit){
	
		$this->unit = $unit;
	}
	
	function setParent($parent){
	
		$this->parent = $parent;
	}
	
	function setEselon($kd_eselon){
	
		$this->eselon = $kd_eselon;
	}
	
	function getKd_unit(){
	
		return $this->kd_unit;
	}
	
	function getUnit(){
	
		return $this->unit;
	}
	
	function getParent(){
	
		return $this->parent;
	}
	
	function getEselon(){
	
		return $this->eselon;
	}
}

class Daftar_unit{
	
	function __construct()
	{
	}
	
	
	function getAll()
	{
		$sql="select * from unit";
		$list_unit=array();            
                $data = mysql_query($sql);
                if($data){
                        while($row = mysql_fetch_assoc($data)){
                                $unit = new Unit();
								$unit->setId($row['kd_unit']);
								$unit->setUnit($row['unit']);
								$unit->setParent($row['kd_parent']);
								$unit->setEselon($row['eselon']);	
								$list_unit[] = $unit;
                        }
                }       
                return $list_unit;

	
	}
	function getById($kd_unit)
	{
		$sql="select * from unit where kd_unit='$kd_unit'";
		$unit=false;            
                $data = mysql_query($sql);
                if($data){
                        while($row = mysql_fetch_assoc($data)){
                                $unit = new Unit();
								$unit->setId($row['kd_unit']);
								$unit->setUnit($row['unit']);
								$unit->setParent($row['kd_parent']);
								$unit->setEselon($row['eselon']);	
                        }
                }       
                return $unit;

	
	}
	
	function getByEselon($eselon)
	{
		$sql="select * from unit where eselon='$eselon'";
		$list_unit=array();            
                $data = mysql_query($sql);
                if($data){
                        while($row = mysql_fetch_assoc($data)){
                                $unit = new Unit();
								$unit->setId($row['kd_unit']);
								$unit->setUnit($row['unit']);
								$unit->setParent($row['kd_parent']);
								$unit->setEselon($row['eselon']);	
								$list_unit[] = $unit;
                        }
                }       
                return $list_unit;

	
	}
	
	function getByParent($parent)
	{
		$sql="select * from unit where kd_parent='$parent'";
		$list_unit=array();            
                $data = mysql_query($sql);
                if($data){
                        while($row = mysql_fetch_assoc($data)){
                                $unit = new Unit();
								$unit->setId($row['kd_unit']);
								$unit->setUnit($row['unit']);
								$unit->setParent($row['kd_parent']);
								$unit->setEselon($row['eselon']);	
								$list_unit[] = $unit;
                        }
                }       
                return $list_unit;

	
	}
	
	function getEselonByUnit($unit)
	{
		$sql="select distinct(eselon) as eselon from unit where kd_unit='$unit'";
		$eselon = false;            
        $data = mysql_query($sql);
                if($data){
                        while($row = mysql_fetch_assoc($data)){
                           $eselon = $row['eselon'];     
                        }
                }       
                return $eselon;

	
	}


}


